package main

import (
	"fmt"
	"strconv"
)

func getLastNumStr(str string) string {
	i := 0
	result := ""
	for i < len(str) {
		lastIndex := i
		for i < len(str)-1 {
			if str[i] != str[i+1] {
				break
			}
			i++
		}
		count := strconv.Itoa(i - lastIndex + 1)
		result += count
		result += string(str[lastIndex])
		i++
	}

	return result
}

func countAndSay(n int) string {
	if n == 1 {
		return "1"
	}

	last := "1"
	for i := 1; i < n; i++ {
		last = getLastNumStr(last)
	}

	return last
}

func main() {
	fmt.Println(countAndSay(3))

}
